package com.itheima.map;

/*
斗地主案例升级版案例的主要步骤
        1.创建HashMap集合，键为编号，值为牌
        2.创建ArrayList集合，存储编号
        3.创建花色和点数的数组
        4.将编号和花色存储到map集合中，将编号单独存储list集合中
        5.使用Collections中的shuffle()方法将list集合进行随机置换
        6.创建玩家和底牌的TreeSet集合，并进行发牌
        7.遍历集合，查看内容
*/

import java.util.*;

public class DouDiZhuDemo2 {
    public static void main(String[] args) {
        HashMap<Integer, String> hm = new HashMap<Integer, String>();
        ArrayList<Integer> al = new ArrayList<Integer>();
        String[] color = {"♠", "♥", "♦", "♣"};
        String[] numbers = {" 3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        int index = 0;
        for (String number : numbers) {   //number循环在前，存入集合中是按照从小到大顺序存的
            for (String s : color) {
                hm.put(index, s + number);
                al.add(index);
                index++;
            }
        }
        hm.put(index, "大🃏");
        al.add(index);
        index++;
        hm.put(index, "小🃏");
        al.add(index);

        Collections.shuffle(al); //洗牌

        TreeSet<Integer> wj1 = new TreeSet<Integer>();
        TreeSet<Integer> wj2 = new TreeSet<Integer>();
        TreeSet<Integer> wj3 = new TreeSet<Integer>();
        TreeSet<Integer> dipai = new TreeSet<Integer>();


        for (int i = 0; i < al.size(); i++) {
            int x = al.get(i);
            if (i >= al.size() - 3) {
                dipai.add(x);
            } else if (i % 3 == 1) {
                wj1.add(x);
            } else if (i % 3 == 2) {
                wj2.add(x);
            } else {
                wj3.add(x);
            }

        }

        lookPoker("wj1", hm, wj1);
        lookPoker("wj2", hm, wj2);
        lookPoker("wj3", hm, wj3);
        lookPoker("dipai", hm, dipai);
    }

    private static void lookPoker(String name, HashMap<Integer, String> hm, TreeSet<Integer> wj) {
        System.out.println(name + "的牌是:");
        for (Integer integer : wj) {
            String s = hm.get(integer);
            System.out.print(s + " ");
        }
        System.out.println();
    }
}
